﻿Namespace helper
    Public Class RSSFeedHelper

        'created by: Sum
        'created date: 28/6/2012


        ''' <summary>
        ''' Get Channel Title
        ''' </summary>
        ''' <param name="url">url</param>
        ''' <returns>Channel Title</returns>
        ''' <remarks></remarks>
        Public Shared Function GetTitle(ByVal url As String) As String
            Dim x As XDocument
            x = XDocument.Load(url)
            Return x.<rss>.<channel>.<title>.FirstOrDefault.Value
        End Function

        ''' <summary>
        ''' Get Feed
        ''' </summary>
        ''' <param name="url">url</param>
        ''' <returns>return list of rss item which include Title,Link and Description</returns>
        ''' <remarks></remarks>
        Public Shared Function GetFeed(ByVal url) As List(Of RSSItem)
            Dim x As XDocument
            x = XDocument.Load(url)
            Dim Items = New List(Of RSSItem)
            Items = (From item In x.<rss>.<channel>.<item> _
                    Select New RSSItem With { _
                        .Title = item.<title>.Value, _
                        .Link = item.<link>.Value, _
                        .Description = item.<description>.Value _
                    }).ToList

            Return Items
        End Function

    End Class

    Public Class RSSItem
        Private _Title As String
        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Private _Link As String
        Public Property Link() As String
            Get
                Return _Link
            End Get
            Set(ByVal value As String)
                _Link = value
            End Set
        End Property

        Private _Description As String
        Public Property Description() As String
            Get
                Return _Description
            End Get
            Set(ByVal value As String)
                _Description = value
            End Set
        End Property



    End Class
End Namespace
